package com.lemon.soft.bookingroom.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.lemon.soft.bookingroom.dto.UserDTO;
import com.lemon.soft.bookingroom.entity.BookingsEntity;
import com.lemon.soft.bookingroom.service.BookingsService;
import com.lemon.soft.bookingroom.util.PageUtils;
import com.lemon.soft.bookingroom.util.R;
import com.lemon.soft.bookingroom.vo.BookingVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lemon.soft.bookingroom.entity.UsersEntity;
import com.lemon.soft.bookingroom.service.UsersService;



/**
 * 
 *
 * @author ${author}
 * @email ${email}
 * @date 2025-05-29 12:38:52
 */
@CrossOrigin
@Tag(name = "用户管理",description = "新增客户，新增员工")
@RestController
@RequestMapping("bookingroom/users")
public class UsersController {
    @Autowired
    private UsersService usersService;
    @Autowired
    private BookingsService bookingsService;

    @Operation(summary = "员工登录")
    @PostMapping("/login")
    public R login(@RequestBody UserDTO users){
          R r=  usersService.login(users);
            return r;
    }
    /**
     * 列表
     */
    @Operation(summary = "查询用户列表", description = "查询用户列表")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = usersService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @Operation(summary = "查询用户信息", description = "根据用户id查询用户订单信息")
    @GetMapping("/info/{userId}")
    public R info(@PathVariable("userId") Integer userId){
		List<BookingVo> bookingsEntities=bookingsService.selectByUserId(userId);
        return R.ok().put("dara", bookingsEntities);
    }

    /**
     * 保存
     */
    @Operation(summary = "新增客户/员工", description = "员工的roleId为2，客户的roleId为3")
    @PostMapping("/save/customer")
    public R save(@RequestBody UsersEntity users){
		usersService.save(users);

        return R.ok();
    }

    /**
     * 修改
     */
    @Operation(summary = "审核", description = "用户状态：0-待审核，1-正常，2-冻结")
    @PostMapping("/update/admin")
    public R update(@RequestBody UsersEntity users){
		usersService.updateById(users);

        return R.ok();
    }
    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Integer[] userIds){
		usersService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
